extends TileMap




func _ready():
	var map_rect = get_used_rect()
	var points = fill(map_rect, 2)
	for pos in points:
		set_cellv(pos, 0)


func fill(map_rect: Rect2, width: int):
	var points = []
	var data = _fill_by_rect(map_rect, width)
	for dir in data:
		var list : Array = data[dir]
		for pos in list:
			points.append(pos + map_rect.position)
	return points


func _fill_by_rect(rect: Rect2, width: int):
	var around : Dictionary = {}
	
	# top
	var top_down_size : Vector2 = Vector2(rect.size.x, width) + Vector2.LEFT.abs() * width * 2
	around[Vector2.UP] = _cell_list(top_down_size, Vector2(0, -width) + Vector2.LEFT * width)
	around[Vector2.DOWN] = _cell_list(top_down_size, Vector2(0, rect.size.y) + Vector2.LEFT * width)
	
	var left_right_size : Vector2 = Vector2(width, rect.size.y)
	around[Vector2.LEFT] = _cell_list(left_right_size, Vector2(-width, 0))
	around[Vector2.RIGHT]  = _cell_list(left_right_size, Vector2(rect.size.x, 0))
	return around

func _cell_list(size: Vector2, offset: Vector2) -> Array:
	var list = []
	for x in size.x:
		for y in size.y:
			list.append(offset + Vector2(x, y))
	return list
